﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.Utils.Menu;
using System.Data;


using QLTTAN.BLL;
using QLTTAN.DTO;
namespace QLTTAN.Form
{
    public partial class frmChiTietLopHoc : DevExpress.XtraEditors.XtraForm
    {
        LopHocBLL LH_BLL;
        PhanCongBLL PC_BLL;
        CT_LopHocBLL CT_LH_BLL;

        public int MaLopSelected = -1;

        public frmChiTietLopHoc()
        {
            InitializeComponent();
        }

        private void frmChiTietLopHoc_Load(object sender, EventArgs e)
        {
            LH_BLL = new LopHocBLL();
            PC_BLL = new PhanCongBLL();
            CT_LH_BLL = new CT_LopHocBLL();

            try
            {
                LopHocDTO LH_DTO = new LopHocDTO();
                LH_DTO.MaLop = MaLopSelected;
                DataRow LopHocSelected = LH_BLL.LopHoc_GetInfo(LH_DTO);

                txtTenLoaiLop.Text = LopHocSelected["TenLoaiLop"].ToString();
                txtChuongTrinhHoc.Text = LopHocSelected["TenChuongTrinh"].ToString();
                txtKhoaHoc.Text = LopHocSelected["TenKhoaHoc"].ToString();
                txtPhongHoc.Text = LopHocSelected["TenPhong"].ToString();
                txtNgayBatDau.Text = LopHocSelected["NgayBatDau"].ToString();
                txtNgayKetThuc.Text = LopHocSelected["NgayKetThuc"].ToString();
                txtNgayHoc.Text = LopHocSelected["DSNgayHoc"].ToString();
                txtCaHoc.Text = LopHocSelected["ThoiGianBatDau"].ToString();

                // Load Giáo Viên của lớp đó.
                PhanCongDTO PC_DTO = new PhanCongDTO();
                PC_DTO.MaLop = LH_DTO.MaLop;
                gridCtrlGiaoVien.DataSource = PC_BLL.PhanCong_Load(PC_DTO);

                 //Load Học Viên của lớp đó.
                CT_LopHocDTO CT_LH_DTO = new CT_LopHocDTO();
                CT_LH_DTO.MaLop = MaLopSelected;
                gridCtrlHocVien.DataSource = CT_LH_BLL.CT_LopHoc_Load(CT_LH_DTO);

            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Thông báo!!!", MessageBoxButtons.OK);
            }
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            frmLopHoc frmLH = new frmLopHoc();
            frmLH.MaLopSelected = MaLopSelected;
            frmLH.ShowDialog();

            frmChiTietLopHoc_Load(sender, e);
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            if (XtraMessageBox.Show("Bạn có chắc chắn muốn thoát khỏi màn hình Chi Tiết Lớp Học?", "Thông báo!!!", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
                this.Close();
        }

        private void gridViewHocVien_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column.FieldName == "STT")
                e.DisplayText = (e.ListSourceRowIndex + 1).ToString();

            if (e.Column.FieldName == "HocPhiConLai")
            {
                e.DisplayText = String.Format("{0:n2} VNĐ", e.Value);
            }

            if (e.Column == GioiTinh)
            {
                e.DisplayText = ((bool)e.Value) == true ? "Nam" : "Nữ";
            }
        }

        private void gridViewGiaoVien_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column.FieldName == "STT")
                e.DisplayText = (e.ListSourceRowIndex + 1).ToString();
        }
    }
}